package com.huawei.boss.xml;

/**
 * 节点实体类
 * @author c00170351
 *
 */
public class XmlElem implements Comparable<XmlElem> {
    private final int currSeq;//节点的序号
    private final int parentSeq;//节点的父节点序号
    private final String tagName;//标签名称
    private final String tagTxt;//标签的内容

    public int getCurrSeq() {
        return currSeq;
    }

    public int getParentSeq() {
        return parentSeq;
    }

    public String getTagName() {
        return tagName;
    }

    public String getTagTxt() {
        return tagTxt;
    }

    public XmlElem(int currSeq, int parentSeq, String tagName, String tagTxt) {
        this.currSeq = currSeq;
        this.parentSeq = parentSeq;
        this.tagName = tagName == null ? "" : tagName;
        this.tagTxt = tagTxt == null ? "" : tagTxt;
    }

    @Override
    public String toString() {
        return "currSeq:" + currSeq + ",parentSeq:" + parentSeq + ",tagName:" + tagName + ",tagTxt:" + tagTxt;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null)
            return false;
        if (!(obj instanceof XmlElem))
            return false;
        XmlElem xmlElem = (XmlElem) obj;
        return xmlElem.getCurrSeq() == this.getCurrSeq() && xmlElem.getParentSeq() == this.getParentSeq()
                && xmlElem.getTagName().equals(this.getTagName()) && xmlElem.getTagTxt().equals(this.getTagTxt());
    }

    public int compareTo(XmlElem o) {
        return this.getCurrSeq() - o.getCurrSeq();
    }
}
